package com.hncc.kumao.dao.impl;
import java.util.Date;
import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Restrictions;
import com.hncc.kumao.dao.IOfflineDownloadTaskDao;
import com.hncc.kumao.entity.OfflineDownloadTask;
/**
 * 数据访问类
 * @author Administrator
 *
 */
public class OfflineDownloadTaskDao extends BaseDao<OfflineDownloadTask> implements IOfflineDownloadTaskDao {

	
	/**
	 * 构建查询条件
	 * @param dep1
	 * @param dep2
	 * @param param
	 * @return
	 */
	public DetachedCriteria getDetachedCriteria(OfflineDownloadTask offlineDownloadTask1,OfflineDownloadTask offlineDownloadTask2,Object param){
		DetachedCriteria dc = DetachedCriteria.forClass(OfflineDownloadTask.class);
		if(offlineDownloadTask1!=null){
		    if(offlineDownloadTask1.getUserId() != null && offlineDownloadTask1.getUserId().trim().length() > 0) {
		        dc.add(Restrictions.eq("userId", offlineDownloadTask1.getUserId()));
		    }
		    if(offlineDownloadTask1.getState() != null && offlineDownloadTask1.getState() >=0 ) {
		        dc.add(Restrictions.eq("state", offlineDownloadTask1.getState()));
		    }
		}		
		return dc;
	}

	/**
	 * 统计任务状态
	 */
    public List getTaskStateInfo() {
        //hql查询语句
        String hql = "select new Map(od.state as state, count(0) as number) "
                + "from OfflineDownloadTask od group by od.state";
        //执行查询
        List list = getHibernateTemplate().find(hql);
        return list;
    }
}

